# writer:sp
# tiem: 2024/9/7 15:48
import random

# 定义一个列表
my_list = ['apple', 'banana', 'cherry']

# 定义每个元素的累积权重
cum_weights = [10, 11, 12]

# 从列表中随机选择一个元素
chosen_element = random.choices(my_list, cum_weights=cum_weights, k=1)

print("Chosen element:", chosen_element[0])

# 从列表中随机选择多个元素
chosen_elements = random.choices(my_list, cum_weights=cum_weights, k=3)

print("Chosen elements:", chosen_elements)
